package com.armed.ejb.sessions;

import com.armed.ejb.transference.Persona;
import com.armed.ejb.transference.helpers.DataReverseTransferHelper;
import com.armed.ejb.transference.helpers.DataTransferHelper;
import com.armed.excepciones.personas.PersonaRepetidaException;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Class PersonasFacade
 *
 *
 * @author init() software
 * @version 08/02/2008 
 */
@Stateless
public class PersonasFacade implements PersonasFacadeRemote 
{
    @PersistenceContext
    private EntityManager em;
    /** Constructor of PersonasFacade */
    public PersonasFacade()
    {
    }

    public void create(Persona personas) throws PersonaRepetidaException
    {
        em.persist(DataReverseTransferHelper.revertPerson(personas));
    }

    public void edit(Persona personas)
    {
        em.merge(DataReverseTransferHelper.revertPerson(personas));
    }

    public void remove(Persona personas)
    {
        em.remove(em.merge(DataReverseTransferHelper.revertPerson(personas)));
    }

    public Persona find(Object id)
    {
        Persona p = null;
        p = DataTransferHelper.copyPerson(em.find(com.armed.ejb.entities.Personas.class, id));
        return null;
    }

    public List<Persona> findAll()
    {
        return DataTransferHelper.copyPersonsToList(em.createQuery("select object(o) from Personas as o").getResultList());
    }
}
